package com.lagou.edu.util;

import java.util.Random;

public class VerifyUtil {
    // 验证码字符集
    private static final char[] CHARS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    // 字符数量
    private static final int SIZE = 6;

    /**
     * 生成随机验证码及图片
     */
    public static String createCode() {
        StringBuffer sb = new StringBuffer();
        // 5.画随机字符
        Random ran = new Random();
        for (int i = 0; i < SIZE; i++) {
            // 取随机字符索引
            int n = ran.nextInt(CHARS.length);
            // 记录字符
            sb.append(CHARS[n]);
        }
       return sb.toString();
    }
}

